package com.wetao.lib_common.utils;

import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;
import android.view.Window;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.view.ContextThemeWrapper;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import kotlin.jvm.JvmStatic;

/**
 * author: zhouyh
 * created on: 2021/6/15 4:34 下午
 * description:视频播放器
 */
public class VideoPlayerUtils {

    @NotNull
    public static final VideoPlayerUtils INSTANCE;

    @JvmStatic
    public static final void hideActionBar(@Nullable Context context) {
        AppCompatActivity var10000 = INSTANCE.getAppCompatActivity(context);
        ActionBar supportActionBar = var10000 != null ? var10000.getSupportActionBar() : null;
        if (supportActionBar != null) {
            supportActionBar.setShowHideAnimationEnabled(false);
            supportActionBar.hide();
        }

        Activity var5 = getActivity(context);
        if (var5 != null) {
            Window var6 = var5.getWindow();
            if (var6 != null) {
                var6.setFlags(1024, 1024);
            }
        }

    }

    @JvmStatic
    public static final void showActionBar(@Nullable Context context) {
        AppCompatActivity var10000 = INSTANCE.getAppCompatActivity(context);
        ActionBar supportActionBar = var10000 != null ? var10000.getSupportActionBar() : null;
        if (supportActionBar != null) {
            supportActionBar.setShowHideAnimationEnabled(false);
            supportActionBar.show();
        }

        Activity var5 = getActivity(context);
        if (var5 != null) {
            Window var6 = var5.getWindow();
            if (var6 != null) {
                var6.clearFlags(1024);
            }
        }

    }

    private final AppCompatActivity getAppCompatActivity(Context context) {
        if (context == null) {
            return null;
        } else if (context instanceof AppCompatActivity) {
            return (AppCompatActivity)context;
        } else {
            return context instanceof ContextThemeWrapper ? this.getAppCompatActivity(((ContextThemeWrapper)context).getBaseContext()) : null;
        }
    }

    @JvmStatic
    @Nullable
    public static final Activity getActivity(@Nullable Context context) {
        if (context == null) {
            return null;
        } else if (context instanceof Activity) {
            return (Activity)context;
        } else {
            return context instanceof ContextWrapper ? getActivity(((ContextWrapper)context).getBaseContext()) : null;
        }
    }

    @JvmStatic
    @Nullable
    public static final Window getWindow(@Nullable Context context) {
        Window var1;
        if (INSTANCE.getAppCompatActivity(context) != null) {
            AppCompatActivity var10000 = INSTANCE.getAppCompatActivity(context);
            var1 = var10000 != null ? var10000.getWindow() : null;
        } else {
            Activity var2 = getActivity(context);
            var1 = var2 != null ? var2.getWindow() : null;
        }

        return var1;
    }

    private VideoPlayerUtils() {
    }

    static {
        VideoPlayerUtils var0 = new VideoPlayerUtils();
        INSTANCE = var0;
    }
}
